/*******************************************************************************
 * 文件名: ConstantsLoader.java
 * 描    述: 常量配置项加载类
 * 创建人: Dean Huang(hudi-112@163.com)
 * 日　期: 2016-05-10
 * 描　述: 文件描述
 * 版　本: 1.0
 *******************************************************************************/

package com.z1.core.config;

import java.util.HashMap;
import java.util.Map;

public class ConstantsLoader {

	private static Map<String, String> props = new HashMap<String, String>();
	
	public static void load(Map<String, String> defMap) {
		if (null != defMap) {
			for (String key : defMap.keySet()) {
				if (null == props.get(key)) {
					props.put(key, defMap.get(key));
				}
			}
		}
		props.putAll(ConfigLoader.getProps());
	}
	
	public static String getProperty(String key) {
		return props.get(key);
	}
	public static String getProperty(String key, String def) {
		String value = props.get(key);
		if (null != value) {
			return value;
		}
		return def;
	}
	
	public static Map<String, String> getProps() {
		return props;
	}
	
	public static Map<String, String> getRegexProps(String regex) {
		Map<String, String> regexMap = new HashMap<String, String>();
		Map<String, String> map = getProps();
		for (String key : map.keySet()) {
			if (key.toString().matches(regex)) {
				regexMap.put(key.toString(), map.get(key));
			}
		}
		
		return regexMap;
	}
	
	public static boolean containsKey(String key) {
		return props.containsKey(key);
	}
	
}
